
** Figure H.18: Consumption event study


use "$datadir/consumption/finaldata_hh_eventtime.dta", clear
	cap drop invshare_sd
	cap drop l_preshockdeposit
	
	** add banking deposit data
	merge m:1  state district using "$datadir/banking/adjusted_deposit.dta", keepusing(state district  preshock_deposit) keep(match) nogenerate 
	**
	g l_preshockdeposit = ln(1+preshock_deposit)
	label var l_preshockdeposit "Log(pre-shock deposits)"
	
	** attach district controls
	merge m:1 district state using "$datadir\districts\districtcontrols.dta", update replace
	drop if (_m == 1 | _m == 2)
	drop _m
	**
	
	* merge with chest measure 
	merge m:1 district state using "$datadir\banking\chest_exposure_full.dta", keepusing(state district invshare_sd) keep(match) nogenerate 
	 
	xtset HH_ID event_time
	*Run the heterogeneity with dummies
	***** FIGURES
	set more off 
	forval i=1/7{
		local j = `i'-4
		g time`i'Xinvshare_sd = (event_time == `j')*invshare_sd	
	}
	
	replace time4Xinvshare_sd = 0 

	  set more off 
	  local month_start = -3	
	  local month_end = 3

	 local controls "(c.log_mrain_adj c.l_income_pre c.l_age_pre c.l_preshockdeposit c.s_status_atm c.s_status_commercialbank c.logpop_T c.share_rural)"
	 foreach var of varlist log_hh_expense_total {
		statsby eff_1=_b[time1Xinvshare_sd] eff_2=_b[time2Xinvshare_sd] eff_3=_b[time3Xinvshare_sd] eff_4=_b[time4Xinvshare_sd] eff_5=_b[time5Xinvshare_sd] eff_6=_b[time6Xinvshare_sd] eff_7=_b[time7Xinvshare_sd] se_1 =_se[time1Xinvshare_sd] se_2 =_se[time2Xinvshare_sd] se_3 = _se[time3Xinvshare_sd] se_4 =_se[time4Xinvshare_sd] se_5 =_se[time5Xinvshare_sd] se_6 =_se[time6Xinvshare_sd] se_7 =_se[time7Xinvshare_sd] , saving("$datadir\coefsSHIF_contr_`var'_rf_survey", replace): reghdfe `var' time1Xinvshare_sd time2Xinvshare_sd time3Xinvshare_sd time4Xinvshare_sd time5Xinvshare_sd time6Xinvshare_sd time7Xinvshare_sd if   event_time >= `month_start' & event_time <= `month_end' , a(HH_ID i.event_time `controls'##i.event_time) vce(cluster district_id)
	 }

	 
	 
***** Graph:
  foreach var in log_hh_expense_total {
	  use "$datadir\coefsSHIF_contr_`var'_rf_survey.dta", clear
	  gen i=1
	  reshape long eff_ se_ , i(i) j(period)
	  drop i
	  rename eff_ eff
	  rename se_ se
	  tset period
	  
	  gen t_10=1.65
	  gen t_5=1.96
	  
	  foreach num in 5 10 {
	  gen low_bound_`num'=eff-(t_`num'*se)
	  gen up_bound_`num'=eff+(t_`num'*se)
	  }
	  replace period=period-4

	  gen temp="`var'"
	  local name="`var'"
	  if temp=="log_hh_expense_total" {
	  local name="total consumption"
	  }
	  
	  drop temp

	  twoway (rcap up_bound_5 low_bound_5 period, lcolor(gray) lstyle(ci)) (scatter eff period, lcolor(black) mcolor(black) msymbol(circle) msize(medium)) , ///
	  legend(off) graphregion(color(white)) xline(1, lwidth(20) lc(gs12)) ylab(,nogrid) xlab(-3(1)3) yline(0, lcolor(gs10) lpattern(dash)) ///
	  xtitle("Survey-time") ytitle("Effect on `name'") xline(0.5, lcolor(red) lpattern(dash))
	  graph export "$outputdir_fig\Figure_H_18.pdf", as(pdf) replace
	  erase "$datadir\coefsSHIF_contr_`var'_rf_survey.dta"
	  clear
	  
  }

